home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / samba / patches / samba-1.002 / samba-1
Encoding:
Text File  |  1996-06-08  |  64.2 KB  |  2,062 lines

  1. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/docs/MIRRORS samba-1.9.16alpha9/docs/MIRRORS
  2. --- samba-1.9.16alpha8/docs/MIRRORS    Tue May 28 23:39:00 1996
  3. +++ samba-1.9.16alpha9/docs/MIRRORS    Sat Jun  8 15:37:41 1996
  4. @@ -6,9 +6,9 @@
  5.  ftp://nimbus.anu.edu.au/pub/tridge/samba
  6.  ftp://sunsite.auc.dk/pub/unix/networking/samba/
  7.  ftp://src.doc.ic.ac.uk/packages/samba/
  8. +ftp://choc.satech.net.au/pub/samba/
  9.  ftp://ftp.warwick.ac.uk/pub/linux/sunsite.unc-mirror/system/Network/samba/
  10.  ftp://sunsite.unc.edu/pub/Linux/system/Network/samba/
  11. -ftp://ftp.choc.apana.org.au/pub/samba/
  12.  ftp://ftp.uni-trier.de/pub/unix/network/samba/
  13.  ftp://ftp.spectrum.titan.com/pub/samba/
  14.  ftp://ftp.demon.co.uk/pub/unix/unix/samba/
  15. @@ -28,4 +28,5 @@
  16.  Http sites include:
  17.  
  18.  http://samba.canberra.edu.au/pub/samba
  19. -http://www.choc.apana.org.au/pub/samba
  20. +http://www.choc.satech.net.au/pub/samba/
  21. +
  22. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/source/Makefile samba-1.9.16alpha9/source/Makefile
  23. --- samba-1.9.16alpha8/source/Makefile    Thu Jun  6 21:57:20 1996
  24. +++ samba-1.9.16alpha9/source/Makefile    Fri Jun  7 15:36:52 1996
  25. @@ -497,11 +497,11 @@
  26.  
  27.  UTILOBJ1 = util.o system.o charset.o kanji.o fault.o smbencrypt.o charcnv.o
  28.  UTILOBJ2 = $(UTILOBJ1) md4.o loadparm.o params.o pcap.o username.o time.o
  29. -UTILOBJ = $(UTILOBJ2) interface.o
  30. +UTILOBJ = $(UTILOBJ2) interface.o 
  31.  PARAMOBJ = $(UTILOBJ) ufc.o smbpass.o access.o 
  32.  SMBDOBJ1 = $(PARAMOBJ) trans2.o message.o dir.o printing.o locking.o
  33.  SMBDOBJ2 = ipc.o reply.o mangle.o chgpasswd.o password.o quotas.o uid.o
  34. -SMBDOBJ = $(SMBDOBJ1) $(SMBDOBJ2) $(VTP_OBJ)
  35. +SMBDOBJ = predict.o $(SMBDOBJ1) $(SMBDOBJ2) $(VTP_OBJ)
  36.  NMBDOBJ1 = $(UTILOBJ) nmblib.o nameresp.o nmbsync.o nameannounce.o namedb.o nameelect.o
  37.  NMBDOBJ = $(NMBDOBJ1) namework.o nameserv.o clientutil.o
  38.  .SUFFIXES:
  39. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/source/byteorder.h samba-1.9.16alpha9/source/byteorder.h
  40. --- samba-1.9.16alpha8/source/byteorder.h    Sat May  4 17:50:23 1996
  41. +++ samba-1.9.16alpha9/source/byteorder.h    Sat Jun  8 15:37:52 1996
  42. @@ -22,6 +22,70 @@
  43.  /*
  44.     This file implements macros for machine independent short and 
  45.     int manipulation
  46. +
  47. +Here is a description of this file that I emailed to the samba list once:
  48. +
  49. +> I am confused about the way that byteorder.h works in Samba. I have
  50. +> looked at it, and I would have thought that you might make a distinction
  51. +> between LE and BE machines, but you only seem to distinguish between 386
  52. +> and all other architectures.
  53. +> 
  54. +> Can you give me a clue?
  55. +
  56. +sure.
  57. +
  58. +The distinction between 386 and other architectures is only there as
  59. +an optimisation. You can take it out completely and it will make no
  60. +difference. The routines (macros) in byteorder.h are totally byteorder
  61. +independent. The 386 optimsation just takes advantage of the fact that
  62. +the x86 processors don't care about alignment, so we don't have to
  63. +align ints on int boundaries etc. If there are other processors out
  64. +there that aren't alignment sensitive then you could also define
  65. +CAREFUL_ALIGNMENT=0 on those processors as well.
  66. +
  67. +Ok, now to the macros themselves. I'll take a simple example, say we
  68. +want to extract a 2 byte integer from a SMB packet and put it into a
  69. +type called uint16 that is in the local machines byte order, and you
  70. +want to do it with only the assumption that uint16 is _at_least_ 16
  71. +bits long (this last condition is very important for architectures
  72. +that don't have any int types that are 2 bytes long)
  73. +
  74. +You do this:
  75. +
  76. +#define CVAL(buf,pos) (((unsigned char *)(buf))[pos])
  77. +#define PVAL(buf,pos) ((unsigned)CVAL(buf,pos))
  78. +#define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8)
  79. +
  80. +then to extract a uint16 value at offset 25 in a buffer you do this:
  81. +
  82. +char *buffer = foo_bar();
  83. +uint16 xx = SVAL(buffer,25);
  84. +
  85. +We are using the byteoder independence of the ANSI C bitshifts to do
  86. +the work. A good optimising compiler should turn this into efficient
  87. +code, especially if it happens to have the right byteorder :-)
  88. +
  89. +I know these macros can be made a bit tidier by removing some of the
  90. +casts, but you need to look at byteorder.h as a whole to see the
  91. +reasoning behind them. byteorder.h defines the following macros:
  92. +
  93. +SVAL(buf,pos) - extract a 2 byte SMB value
  94. +IVAL(buf,pos) - extract a 4 byte SMB value
  95. +SVALS(buf,pos) signed version of SVAL()
  96. +IVALS(buf,pos) signed version of IVAL()
  97. +
  98. +SSVAL(buf,pos,val) - put a 2 byte SMB value into a buffer
  99. +SIVAL(buf,pos,val) - put a 4 byte SMB value into a buffer
  100. +SSVALS(buf,pos,val) - signed version of SSVAL()
  101. +SIVALS(buf,pos,val) - signed version of SIVAL()
  102. +
  103. +RSVAL(buf,pos) - like SVAL() but for NMB byte ordering
  104. +RIVAL(buf,pos) - like IVAL() but for NMB byte ordering
  105. +RSSVAL(buf,pos,val) - like SSVAL() but for NMB ordering
  106. +RSIVAL(buf,pos,val) - like SIVAL() but for NMB ordering
  107. +
  108. +it also defines lots of intermediate macros, just ignore those :-)
  109. +
  110.  */
  111.  
  112.  #undef CAREFUL_ALIGNMENT
  113. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/source/cvs.log samba-1.9.16alpha9/source/cvs.log
  114. --- samba-1.9.16alpha8/source/cvs.log    Thu Jun  6 21:58:16 1996
  115. +++ samba-1.9.16alpha9/source/cvs.log    Sat Jun  8 15:41:17 1996
  116. @@ -1291,3 +1291,171 @@
  117.  Log Message:
  118.  preparing for release of 1.9.16alpha8
  119.  
  120. +
  121. +****************************************
  122. +Date:    Friday June 7, 1996 @ 13:34
  123. +Author:    tridge
  124. +
  125. +Update of /data/cvs/samba/source
  126. +In directory arvidsjaur:/var/tmp/cvs-serv8181
  127. +
  128. +Modified Files:
  129. +    Makefile interface.c loadparm.c loadparm.h namedb.c 
  130. +    nameelect.c nameserv.c namework.c nmbd.c nmbsync.c proto.h 
  131. +    util.c 
  132. +Added Files:
  133. +    predict.c 
  134. +Log Message:
  135. +- added predict.c, moving the routines from util.c
  136. +
  137. +- added iface_count() and iface_n_ip() routines so its easy to loop
  138. +over the local interface list
  139. +
  140. +- made readsize a normal loadparm global
  141. +
  142. +- check for null w in add_domain_entry()
  143. +
  144. +- set the deathtime to time()-1 for doamin entries with servertype==0
  145. +This allows servers that are shutting down to be removed
  146. +
  147. +- add the 0x1c name at startup if we are a WINS server. Previously we
  148. +added it only if we were a master
  149. +
  150. +- loop over interfaces in add_my_domains(), so people don't have to
  151. +have a lmhosts file to get lp_workgroup() on all interfaces
  152. +
  153. +- set add to True for find_workgroupstruct() in nmbsync, and check for
  154. +null return
  155. +
  156. +- remove some ugly "errno = EBADF" bits. they just confused things.
  157. +
  158. +
  159. +
  160. +
  161. +
  162. +****************************************
  163. +Date:    Saturday June 8, 1996 @ 14:33
  164. +Author:    tridge
  165. +
  166. +Update of /data/cvs/samba/source
  167. +In directory arvidsjaur:/var/tmp/cvs-serv272
  168. +
  169. +Modified Files:
  170. +    byteorder.h installscripts.sh interface.c nmblookup.c quotas.c 
  171. +Log Message:
  172. +- added comments to byteorder.h explaining how it works.
  173. +- fixed problem with installscripts if srcdir is not set
  174. +- fixed ptr init bug in interface.c
  175. +- changed default lookup type in nmblookup to match nbtstat under NT
  176. +- new quotas fixes for sunos and solaris
  177. +
  178. +
  179. +
  180. +****************************************
  181. +Date:    Saturday June 8, 1996 @ 14:34
  182. +Author:    tridge
  183. +
  184. +Update of /data/cvs/samba/source
  185. +In directory arvidsjaur:/var/tmp/cvs-serv323
  186. +
  187. +Modified Files:
  188. +    nameannounce.c 
  189. +Log Message:
  190. +patches fromk Luke putting in symbolic names for time constants
  191. +
  192. +
  193. +
  194. +****************************************
  195. +Date:    Saturday June 8, 1996 @ 14:36
  196. +Author:    tridge
  197. +
  198. +Update of /data/cvs/samba/source
  199. +In directory arvidsjaur:/var/tmp/cvs-serv369
  200. +
  201. +Modified Files:
  202. +    namedb.c 
  203. +Log Message:
  204. +moved MSBROWSE into nameserv.h
  205. +
  206. +
  207. +
  208. +
  209. +****************************************
  210. +Date:    Saturday June 8, 1996 @ 14:40
  211. +Author:    tridge
  212. +
  213. +Update of /data/cvs/samba/source
  214. +In directory arvidsjaur:/var/tmp/cvs-serv477
  215. +
  216. +Modified Files:
  217. +    nameelect.c nameserv.h nmbd.c 
  218. +Log Message:
  219. +changes from Luke
  220. +
  221. +
  222. +
  223. +
  224. +
  225. +****************************************
  226. +Date:    Saturday June 8, 1996 @ 14:41
  227. +Author:    tridge
  228. +
  229. +Update of /data/cvs/samba/source
  230. +In directory arvidsjaur:/var/tmp/cvs-serv514
  231. +
  232. +Modified Files:
  233. +    namework.c 
  234. +Log Message:
  235. +changes from Luke
  236. +
  237. +
  238. +
  239. +
  240. +
  241. +****************************************
  242. +Date:    Saturday June 8, 1996 @ 15:36
  243. +Author:    tridge
  244. +
  245. +Update of /data/cvs/samba/docs
  246. +In directory arvidsjaur:/var/tmp/cvs-serv1668
  247. +
  248. +Modified Files:
  249. +    MIRRORS 
  250. +Log Message:
  251. +fixed the apana MIRRORS entry
  252. +
  253. +
  254. +
  255. +
  256. +
  257. +
  258. +****************************************
  259. +Date:    Saturday June 8, 1996 @ 15:37
  260. +Author:    tridge
  261. +
  262. +Update of /data/cvs/samba/source
  263. +In directory arvidsjaur:/var/tmp/cvs-serv1757
  264. +
  265. +Modified Files:
  266. +    nameresp.c nameserv.c nmbd.c proto.h 
  267. +Log Message:
  268. +more changes from Luke
  269. +
  270. +
  271. +
  272. +
  273. +
  274. +
  275. +
  276. +****************************************
  277. +Date:    Saturday June 8, 1996 @ 15:38
  278. +Author:    samba-bu
  279. +
  280. +Update of /data/cvs/samba/source
  281. +In directory arvidsjaur:/samba/samba-bugs/samba/source
  282. +
  283. +Modified Files:
  284. +    version.h 
  285. +Log Message:
  286. +preparing for release of 1.9.16alpha9
  287. +
  288. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/source/installscripts.sh samba-1.9.16alpha9/source/installscripts.sh
  289. --- samba-1.9.16alpha8/source/installscripts.sh    Thu May 30 13:15:57 1996
  290. +++ samba-1.9.16alpha9/source/installscripts.sh    Sat Jun  8 15:37:52 1996
  291. @@ -16,8 +16,8 @@
  292.   fi
  293.  done
  294.  
  295. -cp $SRCDIR/smbtar $BINDIR
  296. -cp $SRCDIR/addtosmbpass $BINDIR
  297. +cp ${SRCDIR}smbtar $BINDIR
  298. +cp ${SRCDIR}addtosmbpass $BINDIR
  299.  echo Setting permissions on scripts
  300.  chmod $INSTALLPERMS $BINDIR/smbtar
  301.  chmod $INSTALLPERMS $BINDIR/addtosmbpass
  302. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/source/interface.c samba-1.9.16alpha9/source/interface.c
  303. --- samba-1.9.16alpha8/source/interface.c    Thu Jun  6 21:42:41 1996
  304. +++ samba-1.9.16alpha9/source/interface.c    Sat Jun  8 15:37:52 1996
  305. @@ -25,6 +25,7 @@
  306.  extern int DEBUGLEVEL;
  307.  
  308.  struct in_addr ipzero;
  309. +struct in_addr ipgrp;
  310.  static struct in_addr default_ip;
  311.  static struct in_addr default_bcast;
  312.  static struct in_addr default_nmask;
  313. @@ -266,6 +267,7 @@
  314.    struct in_addr ip;
  315.  
  316.    ipzero = *interpret_addr2("0.0.0.0");
  317. +  ipgrp = *interpret_addr2("255.255.255.255");
  318.  
  319.    while (next_token(&ptr,token,NULL)) {
  320.      /* parse it into an IP address/netmasklength pair */
  321. @@ -315,6 +317,8 @@
  322.    iface = (struct interface *)malloc(sizeof(*iface));
  323.    if (!iface) return;
  324.  
  325. +  iface->next = NULL;
  326. +
  327.    if (got_ip) {
  328.      iface->ip = default_ip;
  329.    } else {
  330. @@ -386,6 +390,33 @@
  331.    for (i=interfaces;i;i=i->next)
  332.      if (ip_equal(i->bcast,bcast)) return True;
  333.    return False;
  334. +}
  335. +
  336. +/****************************************************************************
  337. +  how many interfaces do we have
  338. +  **************************************************************************/
  339. +int iface_count(void)
  340. +{
  341. +  int ret = 0;
  342. +  struct interface *i;
  343. +
  344. +  for (i=interfaces;i;i=i->next)
  345. +    ret++;
  346. +  return ret;
  347. +}
  348. +
  349. +/****************************************************************************
  350. +  return IP of the Nth interface
  351. +  **************************************************************************/
  352. +struct in_addr *iface_n_ip(int n)
  353. +{
  354. +  struct interface *i;
  355. +  
  356. +  for (i=interfaces;i && n;i=i->next)
  357. +    n--;
  358. +
  359. +  if (i) return &i->ip;
  360. +  return NULL;
  361.  }
  362.  
  363.  static struct interface *iface_find(struct in_addr ip)
  364. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/source/loadparm.c samba-1.9.16alpha9/source/loadparm.c
  365. --- samba-1.9.16alpha8/source/loadparm.c    Thu Jun  6 21:57:21 1996
  366. +++ samba-1.9.16alpha9/source/loadparm.c    Fri Jun  7 15:36:53 1996
  367. @@ -56,7 +56,6 @@
  368.  BOOL bLoaded = False;
  369.  
  370.  extern int DEBUGLEVEL;
  371. -extern int ReadSize;
  372.  extern pstring user_socket_options;
  373.  
  374.  #ifndef GLOBAL_NAME
  375. @@ -149,6 +148,7 @@
  376.    int syslog;
  377.    int os_level;
  378.    int max_ttl;
  379. +  int ReadSize;
  380.    BOOL bWINSsupport;
  381.    BOOL bWINSproxy;
  382.    BOOL bPreferredMaster;
  383. @@ -409,7 +409,7 @@
  384.    {"keepalive",        P_INTEGER, P_GLOBAL, &keepalive,                 NULL},
  385.    {"deadtime",         P_INTEGER, P_GLOBAL, &Globals.deadtime,          NULL},
  386.    {"time offset",      P_INTEGER, P_GLOBAL, &extra_time_offset,         NULL},
  387. -  {"read size",        P_INTEGER, P_GLOBAL, &ReadSize,                  NULL},
  388. +  {"read size",        P_INTEGER, P_GLOBAL, &Globals.ReadSize,          NULL},
  389.  #ifdef KANJI
  390.    {"coding system",    P_INTEGER, P_GLOBAL, &coding_system, handle_coding_system},
  391.  #endif /* KANJI */
  392. @@ -582,6 +582,7 @@
  393.    Globals.bBrowseList = True;
  394.    Globals.bWINSsupport = True;
  395.    Globals.bWINSproxy = False;
  396. +  Globals.ReadSize = 16*1024;
  397.  
  398.  #ifdef KANJI
  399.    coding_system = interpret_coding_system (KANJI, SJIS_CODE);
  400. @@ -735,6 +736,7 @@
  401.  FN_GLOBAL_INTEGER(lp_maxpacket,&Globals.max_packet)
  402.  FN_GLOBAL_INTEGER(lp_keepalive,&keepalive)
  403.  FN_GLOBAL_INTEGER(lp_passwordlevel,&Globals.pwordlevel)
  404. +FN_GLOBAL_INTEGER(lp_readsize,&Globals.ReadSize)
  405.  FN_GLOBAL_INTEGER(lp_deadtime,&Globals.deadtime)
  406.  FN_GLOBAL_INTEGER(lp_maxprotocol,&Globals.maxprotocol)
  407.  FN_GLOBAL_INTEGER(lp_security,&Globals.security)
  408. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/source/loadparm.h samba-1.9.16alpha9/source/loadparm.h
  409. --- samba-1.9.16alpha8/source/loadparm.h    Thu Jun  6 21:57:21 1996
  410. +++ samba-1.9.16alpha9/source/loadparm.h    Fri Jun  7 15:36:53 1996
  411. @@ -93,6 +93,7 @@
  412.  extern int  lp_lpqcachetime(void);
  413.  extern int  lp_syslog(void);
  414.  extern int  lp_deadtime(void);
  415. +extern int  lp_readsize(void);
  416.  extern int  lp_debuglevel(void);
  417.  extern int  lp_maxprotocol(void);
  418.  extern int  lp_maxpacket(void);
  419. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/source/nameannounce.c samba-1.9.16alpha9/source/nameannounce.c
  420. --- samba-1.9.16alpha8/source/nameannounce.c    Thu Jun  6 21:57:21 1996
  421. +++ samba-1.9.16alpha9/source/nameannounce.c    Sat Jun  8 15:37:52 1996
  422. @@ -51,7 +51,6 @@
  423.  
  424.  /* what server type are we currently */
  425.  
  426. -#define MSBROWSE "\001\002__MSBROWSE__\002"
  427.  #define BROWSE_MAILSLOT "\\MAILSLOT\\BROWSE"
  428.  
  429.  /****************************************************************************
  430. @@ -124,7 +123,7 @@
  431.    int tok;
  432.    
  433.    if (!lastrun) lastrun = t;
  434. -  if (t < lastrun + 1*60) return;
  435. +  if (t < lastrun + CHECK_TIME_ANNOUNCE_BACKUP * 60) return;
  436.    lastrun = t;
  437.    
  438.    for (tok = 0; tok <= workgroup_count; tok++)
  439. @@ -215,7 +214,8 @@
  440.        if (work->needannounce) {
  441.          /* drop back to a max 3 minute announce - this is to prevent a
  442.             single lost packet from stuffing things up for too long */
  443. -        work->announce_interval = MIN(work->announce_interval,3*60);
  444. +        work->announce_interval = MIN(work->announce_interval, 
  445. +                      CHECK_TIME_MIN_HOST_ANNCE*60);
  446.          work->lastannounce_time = t - (work->announce_interval+1);
  447.        }
  448.        
  449. @@ -224,7 +224,7 @@
  450.            (t - work->lastannounce_time) < work->announce_interval)
  451.          continue;
  452.        
  453. -      if (work->announce_interval < 12*60) 
  454. +      if (work->announce_interval < CHECK_TIME_MAX_HOST_ANNCE * 60) 
  455.          work->announce_interval += 60;
  456.        
  457.        work->lastannounce_time = t;
  458. @@ -343,11 +343,8 @@
  459.    time_t t = time(NULL);
  460.    BOOL am_master = False; /* are we a master of some sort? :-) */
  461.  
  462. -#ifdef TEST_CODE
  463. -  if (last && (t-last < 2*60)) return;
  464. -#else
  465. -  if (last && (t-last < 15*60)) return; 
  466. -#endif
  467. +  if (last && (t-last < CHECK_TIME_MST_ANNOUNCE * 60)) 
  468. +    return; 
  469.  
  470.    last = t;
  471.  
  472. @@ -425,7 +422,7 @@
  473.            ip = *interpret_addr2(lp_domain_controller());
  474.            
  475.            if (zero_ip(ip)) {
  476. -        ip = *iface_bcast(d->bcast_ip);
  477. +        ip = d->bcast_ip;
  478.          bcast = True;
  479.            }
  480.  
  481. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/source/namedb.c samba-1.9.16alpha9/source/namedb.c
  482. --- samba-1.9.16alpha8/source/namedb.c    Thu Jun  6 21:57:21 1996
  483. +++ samba-1.9.16alpha9/source/namedb.c    Sat Jun  8 15:37:53 1996
  484. @@ -38,6 +38,8 @@
  485.  extern pstring myname;
  486.  extern pstring scope;
  487.  
  488. +extern struct in_addr ipgrp;
  489. +
  490.  /* this is our browse master/backup cache database */
  491.  struct browse_cache_record *browserlist = NULL;
  492.  
  493. @@ -55,9 +57,6 @@
  494.              SV_TYPE_TIME_SOURCE | SV_TYPE_SERVER_UNIX | \
  495.              SV_TYPE_PRINTQ_SERVER | SV_TYPE_POTENTIAL_BROWSER)
  496.  
  497. -/* here are my election parameters */
  498. -#define MSBROWSE "\001\002__MSBROWSE__\002"
  499. -
  500.  
  501.  /****************************************************************************
  502.    add a workgroup into the domain list
  503. @@ -449,7 +448,7 @@
  504.    struct domain_record *d;
  505.    struct in_addr ip;
  506.    
  507. -  ip = *interpret_addr2("255.255.255.255");
  508. +  ip = ipgrp;
  509.    
  510.    if (zero_ip(source_ip)) 
  511.      source_ip = *iface_bcast(source_ip);
  512. @@ -460,6 +459,8 @@
  513.      {
  514.        struct work_record *w = find_workgroupstruct(d, name, add);
  515.        
  516. +      if (!w) return NULL;
  517. +
  518.        /* add WORKGROUP(1e) and WORKGROUP(00) entries into name database
  519.       or register with WINS server, if it's our workgroup */
  520.        if (strequal(lp_workgroup(), name))
  521. @@ -586,7 +587,8 @@
  522.    if (ismybcast(d->bcast_ip) &&
  523.        strequal(lp_workgroup(),work->work_group))
  524.      {
  525. -      servertype |= SV_TYPE_LOCAL_LIST_ONLY;
  526. +      if (servertype)
  527. +    servertype |= SV_TYPE_LOCAL_LIST_ONLY;
  528.      }
  529.    else
  530.      {
  531. @@ -599,6 +601,9 @@
  532.    strupper(s->serv.name);
  533.    s->serv.type  = servertype;
  534.    s->death_time = ttl?time(NULL)+ttl*3:0;
  535. +
  536. +  if (servertype == 0)
  537. +    s->death_time = time(NULL)-1;
  538.    
  539.    /* for a domain entry, the comment field refers to the server name */
  540.    
  541. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/source/nameelect.c samba-1.9.16alpha9/source/nameelect.c
  542. --- samba-1.9.16alpha8/source/nameelect.c    Thu Jun  6 21:57:21 1996
  543. +++ samba-1.9.16alpha9/source/nameelect.c    Sat Jun  8 15:37:53 1996
  544. @@ -45,7 +45,6 @@
  545.  
  546.  #define AM_MASTER(work) (work->ServerType & SV_TYPE_MASTER_BROWSER)
  547.  
  548. -#define MSBROWSE "\001\002__MSBROWSE__\002"
  549.  #define BROWSE_MAILSLOT "\\MAILSLOT\\BROWSE"
  550.  
  551.  extern struct domain_record *domainlist;
  552. @@ -61,7 +60,9 @@
  553.    struct domain_record *d;
  554.  
  555.    if (!lastrun) lastrun = t;
  556. -  if (t < lastrun + 5*60) return;
  557. +  if (t < lastrun + CHECK_TIME_MST_BROWSE * 60) 
  558. +    return;
  559. +
  560.    lastrun = t;
  561.  
  562.    dump_workgroups();
  563. @@ -108,16 +109,16 @@
  564.      }
  565.    else
  566.      {
  567. -      DEBUG(2,("no master browser for persistent entry %s %s\n",
  568. -           work->work_group, inet_ntoa(d->bcast_ip)));
  569. +      /* XXXX note: this will delete entries that have been added in by
  570. +     lmhosts as well. a flag to ensure that these are not deleted may
  571. +     be considered */
  572. +      
  573. +      /* workgroup with no master browser is not the default workgroup:
  574. +     it's also not on our subnet. therefore delete it: it can be
  575. +     recreated dynamically */
  576.        
  577. -      /* XXXX oh dear. we are going to have problems here. the
  578. -     entry is a persistent one, there isn't anyone responsible
  579. -     for this workgroup up and running, yet we can't find it
  580. -     and we are going to continually have name_queries until
  581. -     a master browser is found for this workgroup on the
  582. -     remote subnet.
  583. -     */
  584. +      send_election(d, work->work_group, 0, 0, myname);
  585. +      remove_workgroup(d, work);      
  586.      }
  587.  }
  588.  
  589. @@ -177,9 +178,7 @@
  590.        DEBUG(4,("Domain master: adding names...\n"));
  591.        
  592.        /* add domain master and domain member names or register with WINS */
  593. -      add_name_entry(work->work_group,0x1b,NB_ACTIVE         );
  594. -      add_name_entry(work->work_group,0x1c,NB_ACTIVE|NB_GROUP);
  595. -      
  596. +      add_name_entry(work->work_group,0x1b,NB_ACTIVE);
  597.        work->ServerType |= SV_TYPE_DOMAIN_MASTER;
  598.        
  599.        if (lp_domain_logons())
  600. @@ -215,7 +214,6 @@
  601.    work->ElectionCriterion &= ~0x4;
  602.    
  603.    remove_name_entry(work->work_group,0x1b);
  604. -  remove_name_entry(work->work_group,0x1c);
  605.    remove_name_entry(work->work_group,0x1d);
  606.    remove_name_entry(MSBROWSE        ,0x01);
  607.  }
  608. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/source/nameresp.c samba-1.9.16alpha9/source/nameresp.c
  609. --- samba-1.9.16alpha8/source/nameresp.c    Thu Jun  6 21:57:21 1996
  610. +++ samba-1.9.16alpha9/source/nameresp.c    Sat Jun  8 15:37:53 1996
  611. @@ -103,9 +103,9 @@
  612.  /****************************************************************************
  613.    reply to a netbios name packet 
  614.    ****************************************************************************/
  615. -void reply_netbios_packet(struct packet_struct *p1,int trn_id,int rcode,int opcode,
  616. -              struct nmb_name *rr_name,int rr_type,int rr_class,int ttl,
  617. -              char *data,int len)
  618. +void reply_netbios_packet(struct packet_struct *p1,int trn_id,int rcode,
  619. +              int opcode,BOOL recurse,struct nmb_name *rr_name,
  620. +              int rr_type,int rr_class,int ttl,char *data,int len)
  621.  {
  622.    struct packet_struct p;
  623.    struct nmb_packet *nmb = &p.packet.nmb;
  624. @@ -126,7 +126,7 @@
  625.    nmb->header.opcode = opcode;
  626.    nmb->header.response = True;
  627.    nmb->header.nm_flags.bcast = False;
  628. -  nmb->header.nm_flags.recursion_available = True;
  629. +  nmb->header.nm_flags.recursion_available = recurse;
  630.    nmb->header.nm_flags.recursion_desired = True;
  631.    nmb->header.nm_flags.trunc = False;
  632.    nmb->header.nm_flags.authoritative = True;
  633. @@ -275,11 +275,9 @@
  634.  /****************************************************************************
  635.    create a name query response record
  636.    **************************************************************************/
  637. -static struct name_response_record *make_name_query_record(
  638. -                               enum cmd_type cmd,int id,int fd,
  639. -                               char *name,int type,
  640. -                               BOOL bcast,BOOL recurse,
  641. -                               struct in_addr ip)
  642. +static struct name_response_record *
  643. +make_name_query_record(enum cmd_type cmd,int id,int fd,char *name,int type,
  644. +               BOOL bcast,BOOL recurse,struct in_addr ip)
  645.  {
  646.    struct name_response_record *n;
  647.      
  648. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/source/nameserv.c samba-1.9.16alpha9/source/nameserv.c
  649. --- samba-1.9.16alpha8/source/nameserv.c    Thu Jun  6 21:57:21 1996
  650. +++ samba-1.9.16alpha9/source/nameserv.c    Sat Jun  8 15:37:53 1996
  651. @@ -31,14 +31,13 @@
  652.  extern int ClientNMB;
  653.  extern int ClientDGRAM;
  654.  
  655. -enum name_search { FIND_SELF, FIND_GLOBAL };
  656. -
  657.  extern int DEBUGLEVEL;
  658.  
  659.  extern pstring scope;
  660.  extern BOOL CanRecurse;
  661.  extern pstring myname;
  662.  extern struct in_addr ipzero;
  663. +extern struct in_addr ipgrp;
  664.  
  665.  /* netbios names database */
  666.  struct name_record *namelist;
  667. @@ -96,6 +95,7 @@
  668.    }
  669.  }
  670.  
  671. +
  672.  /****************************************************************************
  673.    find a name in the domain database namelist 
  674.    search can be:
  675. @@ -103,28 +103,19 @@
  676.    FIND_GLOBAL - the name can be anyone. first look on the client's
  677.                  subnet, then the server's subnet, then all subnets.
  678.    **************************************************************************/
  679. -static struct name_record *find_name_search(struct nmb_name *name, 
  680. +static struct name_record *find_name_search(struct nmb_name *name,
  681.                          enum name_search search,
  682.                          struct in_addr ip)
  683.  {
  684.    struct name_record *ret;
  685.    
  686. -  /* any number of winpopup names can be added. must search by ip as 
  687. -     well */
  688. -  if (name->name_type != 0x3) ip = ipzero;
  689. -  
  690.    for (ret = namelist; ret; ret = ret->next)
  691.      {
  692. -      if (name_equal(&ret->name,name))
  693. -    {
  694. -      /* self search: self names only */
  695. -      if (search == FIND_SELF && ret->source != SELF) continue;
  696. -      
  697. -      if (zero_ip(ip) || ip_equal(ip, ret->ip))
  698. -        {
  699. -          return ret;
  700. -        }
  701. -    }
  702. +      if (!name_equal(&ret->name,name)) continue;
  703. +
  704. +      if (search == FIND_SELF && ret->source != SELF) continue;
  705. +      
  706. +      return ret;
  707.      }
  708.    
  709.    return NULL;
  710. @@ -267,8 +258,31 @@
  711.    add_netbios_entry("*",0x0,NB_ACTIVE,0,SELF,ip,False);
  712.    add_netbios_entry("__SAMBA__",0x20,NB_ACTIVE,0,SELF,ip,False);
  713.    add_netbios_entry("__SAMBA__",0x00,NB_ACTIVE,0,SELF,ip,False);
  714. +
  715. +  if (lp_wins_support()) {
  716. +    /* the 0x1c name gets added by any WINS server it seems */
  717. +    add_name_entry(my_workgroup(),0x1c,NB_ACTIVE|NB_GROUP);      
  718. +  }
  719. +}
  720. +
  721. +/****************************************************************************
  722. +  remove all the samba names... from a WINS server if necessary.
  723. +  **************************************************************************/
  724. +void remove_my_names()
  725. +{
  726. +  struct name_record *n;
  727. +  
  728. +  for (n = namelist; n; n = n->next)
  729. +    {
  730. +      if (n->source == SELF)
  731. +    {
  732. +      /* get all SELF names removed from the WINS server's database */
  733. +      remove_name_entry(n->name.name, n->name.name_type);
  734. +    }
  735. +    }
  736.  }
  737.  
  738. +
  739.  /*******************************************************************
  740.    refresh my own names
  741.    ******************************************************************/
  742. @@ -316,8 +330,8 @@
  743.  
  744.  
  745.  /****************************************************************************
  746. -response for a reg release received
  747. -**************************************************************************/
  748. +  response for a reg release received
  749. +  **************************************************************************/
  750.  void response_name_release(struct packet_struct *p)
  751.  {
  752.    struct nmb_packet *nmb = &p->packet.nmb;
  753. @@ -345,8 +359,8 @@
  754.  
  755.  
  756.  /****************************************************************************
  757. -reply to a name release
  758. -****************************************************************************/
  759. +  reply to a name release
  760. +  ****************************************************************************/
  761.  void reply_name_release(struct packet_struct *p)
  762.  {
  763.    struct nmb_packet *nmb = &p->packet.nmb;
  764. @@ -361,12 +375,12 @@
  765.    putip((char *)&ip,&nmb->additional->rdata[2]);  
  766.    
  767.    DEBUG(3,("Name release on name %s rcode=%d\n",
  768. -       namestr(&nmb->question.question_name),rcode));
  769. +        namestr(&nmb->question.question_name),rcode));
  770.    
  771.    n = find_name_search(&nmb->question.question_name, FIND_GLOBAL, ip);
  772.    
  773.    /* XXXX under what conditions should we reject the removal?? */
  774. -  if (n && n->nb_flags == nb_flags && ip_equal(n->ip,ip))
  775. +  if (n && n->nb_flags == nb_flags)
  776.      {
  777.        /* success = True;
  778.       rcode = 6; */
  779. @@ -377,27 +391,24 @@
  780.    
  781.    if (bcast) return;
  782.    
  783. -  /*if (success)*/
  784. -  {
  785. -    rdata[0] = nb_flags;
  786. -    rdata[1] = 0;
  787. -    putip(&rdata[2],(char *)&ip);
  788. -  }
  789. +  rdata[0] = nb_flags;
  790. +  rdata[1] = 0;
  791. +  putip(&rdata[2],(char *)&ip);
  792.    
  793.    /* Send a NAME RELEASE RESPONSE */
  794. -  reply_netbios_packet(p,nmb->header.name_trn_id,rcode,opcode,
  795. +  reply_netbios_packet(p,nmb->header.name_trn_id,
  796. +               rcode,opcode,True,
  797.                 &nmb->question.question_name,
  798.                 nmb->question.question_type,
  799.                 nmb->question.question_class,
  800.                 0,
  801. -               rdata, 6 /*success ? 6 : 0*/);
  802. -  /* XXXX reject packet never tested: cannot tell what to do */
  803. +               rdata, 6);
  804.  }
  805.  
  806.  
  807.  /****************************************************************************
  808. -response for a reg request received
  809. -**************************************************************************/
  810. +  response for a reg request received
  811. +  **************************************************************************/
  812.  void response_name_reg(struct packet_struct *p)
  813.  {
  814.    struct nmb_packet *nmb = &p->packet.nmb;
  815. @@ -428,38 +439,45 @@
  816.  
  817.  
  818.  /****************************************************************************
  819. -reply to a reg request
  820. -**************************************************************************/
  821. +  reply to a reg request
  822. +  **************************************************************************/
  823.  void reply_name_reg(struct packet_struct *p)
  824.  {
  825.    struct nmb_packet *nmb = &p->packet.nmb;
  826.    struct nmb_name *question = &nmb->question.question_name;
  827. -  char *qname = nmb->question.question_name.name;
  828. -  int name_type = nmb->question.question_name.name_type;
  829. +  
  830. +  struct nmb_name *reply_name = question;
  831. +  char *qname = question->name;
  832. +  int name_type  = question->name_type;
  833. +  int name_class = nmb->question.question_class;
  834.    
  835.    BOOL bcast = nmb->header.nm_flags.bcast;
  836.    
  837.    int ttl = GET_TTL(nmb->additional->ttl);
  838.    int nb_flags = nmb->additional->rdata[0];
  839. -  BOOL group = (nb_flags&0x80);
  840. +  BOOL group = NAME_GROUP(nb_flags);
  841.    int rcode = 0;  
  842.    int opcode = nmb->header.opcode;  
  843. +  
  844.    struct name_record *n = NULL;
  845. -  int success = True;
  846. +  BOOL success = True;
  847. +  BOOL recurse = True; /* true if samba replies yes/no: false if caller */
  848. +  /* must challenge the current owner */
  849.    char rdata[6];
  850. -  struct in_addr ip, from_ip;
  851.    
  852. -  putip((char *)&from_ip,&nmb->additional->rdata[2]);
  853. -  ip = from_ip;
  854. +  struct in_addr ip, from_ip;
  855.    
  856.    DEBUG(3,("Name registration for name %s at %s rcode=%d\n",
  857.         namestr(question),inet_ntoa(ip),rcode));
  858.    
  859. +  putip((char *)&from_ip,&nmb->additional->rdata[2]);
  860. +  ip = from_ip;
  861. +  
  862.    if (group)
  863.      {
  864.        /* apparently we should return 255.255.255.255 for group queries
  865.       (email from MS) */
  866. -      ip = *interpret_addr2("255.255.255.255");
  867. +      ip = ipgrp;
  868.      }
  869.    
  870.    /* see if the name already exists */
  871. @@ -467,19 +485,62 @@
  872.    
  873.    if (n)
  874.      {
  875. -      if (!group && !ip_equal(ip,n->ip) && question->name_type != 0x3)
  876. +      if (!group) /* unique names */
  877.      {
  878. -      if (n->source == SELF)
  879. +      if (n->source == SELF || NAME_GROUP(n->nb_flags))
  880.          {
  881. +          /* no-one can register one of samba's names, nor can they
  882. +         register a name that's a group name as a unique name */
  883. +          
  884.            rcode = 6;
  885.            success = False;
  886.          }
  887. +      else if(!ip_equal(ip, n->ip))
  888. +        {
  889. +          /* hm. this unique name doesn't belong to them. */
  890. +          
  891. +          /* XXXX rfc1001.txt says:
  892. +           * if we are doing secured WINS, we must send a Wait-Acknowledge
  893. +           * packet (WACK) to the person who wants the name, then do a
  894. +           * name query on the person who currently owns the unique name.
  895. +           * if the current owner is alive, the person who wants the name
  896. +           * can't have it. if they are not alive, they can.
  897. +           *
  898. +           * if we are doing non-secure WINS (which is much simpler) then
  899. +           * we send a message to the person wanting the name saying 'he
  900. +           * owns this name: i don't want to hear from you ever again
  901. +           * until you've checked with him if you can have it!'. we then
  902. +           * abandon the registration. once the person wanting the name
  903. +           * has checked with the current owner, they will repeat the
  904. +           * registration packet if the current owner is dead or doesn't
  905. +           * want the name.
  906. +           */
  907. +          
  908. +          /* non-secured WINS implementation: caller is responsible
  909. +         for checking with current owner of name, then getting back
  910. +         to us... IF current owner no longer owns the unique name */
  911. +          
  912. +          rcode = 0;
  913. +          success = False;
  914. +          recurse = False;
  915. +          
  916. +          /* we inform on the current owner to the caller (which is
  917. +         why it's non-secure */
  918. +          
  919. +          reply_name = &n->name;
  920. +          
  921. +          /* name_type  = ?;
  922. +         name_class = ?;
  923. +         XXXX sorry, guys: i really can't see what name_type
  924. +         and name_class should be set to according to rfc1001 */
  925. +        }
  926.        else
  927.          {
  928. +          /* XXXX removed code that checked with the owner of a name */
  929. +          
  930.            n->ip = ip;
  931.            n->death_time = ttl?p->timestamp+ttl*3:0;
  932. -          DEBUG(3,("%s changed owner to %s\n",
  933. -               namestr(&n->name),inet_ntoa(n->ip)));
  934. +          DEBUG(3,("%s owner: %s\n",namestr(&n->name),inet_ntoa(n->ip)));
  935.          }
  936.      }
  937.        else
  938. @@ -494,81 +555,59 @@
  939.    else
  940.      {
  941.        /* add the name to our subnet/name database */
  942. -      n = add_netbios_entry(qname,name_type,nb_flags,ttl,REGISTER,ip,False);
  943. +      n = add_netbios_entry(qname,name_type,nb_flags,ttl,REGISTER,ip,True);
  944.      }
  945.    
  946.    if (bcast) return;
  947.    
  948. -  update_from_reg(nmb->question.question_name.name,
  949. -          nmb->question.question_name.name_type, from_ip);
  950. -  
  951. -  /* XXXX don't know how to reject a name register: stick info in anyway
  952. -     and guess that it doesn't matter if info is there! */
  953. -  /*if (success)*/
  954. -  {
  955. -    rdata[0] = nb_flags;
  956. -    rdata[1] = 0;
  957. -    putip(&rdata[2],(char *)&ip);
  958. -  }
  959. +  if (success)
  960. +    {
  961. +      update_from_reg(nmb->question.question_name.name,
  962. +              nmb->question.question_name.name_type, from_ip);
  963. +    }
  964.    
  965. -  /* Send a NAME REGISTRATION RESPONSE */
  966. -  reply_netbios_packet(p,nmb->header.name_trn_id,rcode,opcode,
  967. -               &nmb->question.question_name,
  968. -               nmb->question.question_type,
  969. -               nmb->question.question_class,
  970. +  rdata[0] = nb_flags;
  971. +  rdata[1] = 0;
  972. +  putip(&rdata[2],(char *)&ip);
  973. +  
  974. +  /* Send a NAME REGISTRATION RESPONSE (pos/neg)
  975. +     or and END-NODE CHALLENGE REGISTRATION RESPONSE */
  976. +  reply_netbios_packet(p,nmb->header.name_trn_id,
  977. +               rcode,opcode,recurse,
  978. +               reply_name, name_type, name_class,
  979.                 ttl,
  980. -               rdata, 6 /*success ? 6 : 0*/);
  981. +               rdata, 6);
  982.  }
  983.  
  984.  
  985.  /****************************************************************************
  986. -reply to a name status query
  987. -****************************************************************************/
  988. +  reply to a name status query
  989. +  ****************************************************************************/
  990.  void reply_name_status(struct packet_struct *p)
  991.  {
  992.    struct nmb_packet *nmb = &p->packet.nmb;
  993.    char *qname   = nmb->question.question_name.name;
  994.    int ques_type = nmb->question.question_name.name_type;
  995. -  BOOL wildcard = (qname[0] == '*'); 
  996.    char rdata[MAX_DGRAM_SIZE];
  997. -  char *countptr, *buf;
  998. -  int count, names_added;
  999. +  char *countptr, *buf, *bufend;
  1000. +  int names_added;
  1001.    struct name_record *n;
  1002.    
  1003.    DEBUG(3,("Name status for name %s %s\n",
  1004. -       namestr(&nmb->question.question_name), inet_ntoa(p->ip)));
  1005. +        namestr(&nmb->question.question_name), inet_ntoa(p->ip)));
  1006.    
  1007. -  /* find a name: if it's a wildcard, search the entire database.
  1008. -     if not, search for source SELF names only */
  1009. -  n = find_name_search(&nmb->question.question_name,
  1010. -               wildcard ? FIND_GLOBAL : FIND_SELF, p->ip);
  1011. -  
  1012. -  if (!wildcard && (!n || n->source != SELF)) return;
  1013. -  
  1014. -  for (count=0, n = namelist ; n; n = n->next)
  1015. -    {
  1016. -      int name_type = n->name.name_type;
  1017. -      
  1018. -      if (n->source != SELF) continue;
  1019. -      
  1020. -      if (name_type >= 0x1b && name_type <= 0x20 && 
  1021. -      ques_type >= 0x1b && ques_type <= 0x20)
  1022. -    {
  1023. -      if (!strequal(qname, n->name.name)) continue;
  1024. -    }
  1025. -      
  1026. -      count++;
  1027. -    }
  1028. +  n = find_name_search(&nmb->question.question_name,FIND_GLOBAL, p->ip);
  1029.    
  1030. +  if (!n) return;
  1031. +    
  1032.    /* XXXX hack, we should calculate exactly how many will fit */
  1033. -  count = MIN(count,(sizeof(rdata) - 64) / 18);
  1034. -  
  1035. +  bufend = &rdata[MAX_DGRAM_SIZE] - 18;
  1036.    countptr = buf = rdata;
  1037.    buf += 1;
  1038.    
  1039.    names_added = 0;
  1040.    
  1041. -  for (n = namelist ; n && count >= 0; n = n->next) 
  1042. +  for (n = namelist ; n && buf < bufend; n = n->next) 
  1043.      {
  1044.        int name_type = n->name.name_type;
  1045.        
  1046. @@ -577,7 +616,7 @@
  1047.        /* start with first bit of putting info in buffer: the name */
  1048.        
  1049.        bzero(buf,18);
  1050. -      StrnCpy(buf,n->name.name,15);
  1051. +      sprintf(buf,"%-15.15s",n->name.name);
  1052.        strupper(buf);
  1053.        
  1054.        /* now check if we want to exclude other workgroup names
  1055. @@ -597,15 +636,9 @@
  1056.        
  1057.        buf += 18;
  1058.        
  1059. -      count--;
  1060.        names_added++;
  1061.      }
  1062. -  
  1063. -  if (count < 0)
  1064. -    {
  1065. -      DEBUG(3, (("too many names: missing a few!\n")));
  1066. -    }
  1067. -  
  1068. +    
  1069.    SCVAL(countptr,0,names_added);
  1070.    
  1071.    /* XXXXXXX we should fill in more fields of the statistics structure */
  1072. @@ -621,7 +654,8 @@
  1073.    buf += 64;
  1074.    
  1075.    /* Send a POSITIVE NAME STATUS RESPONSE */
  1076. -  reply_netbios_packet(p,nmb->header.name_trn_id,0,0,
  1077. +  reply_netbios_packet(p,nmb->header.name_trn_id,
  1078. +               0,0,True,
  1079.                 &nmb->question.question_name,
  1080.                 nmb->question.question_type,
  1081.                 nmb->question.question_class,
  1082. @@ -631,10 +665,11 @@
  1083.  
  1084.  
  1085.  /***************************************************************************
  1086. -reply to a name query
  1087. -****************************************************************************/
  1088. -struct name_record *search_for_name(struct nmb_name *question,
  1089. -                    struct in_addr ip, int Time, int search)
  1090. +  reply to a name query
  1091. +  ****************************************************************************/
  1092. +static struct name_record *search_for_name(struct nmb_name *question,
  1093. +                       struct in_addr ip, int Time, 
  1094. +                       enum name_search search)
  1095.  {
  1096.    int name_type = question->name_type;
  1097.    char *qname = question->name;
  1098. @@ -644,7 +679,7 @@
  1099.    
  1100.    DEBUG(3,("Search for %s from %s - ", namestr(question), inet_ntoa(ip)));
  1101.    
  1102. -  /* first look up name in cache */
  1103. +  /* first look up name in cache. use ip as well as name to locate it */
  1104.    n = find_name_search(question,search,ip);
  1105.    
  1106.    /* now try DNS lookup. */
  1107. @@ -670,14 +705,12 @@
  1108.        /* no luck with DNS. We could possibly recurse here XXXX */
  1109.        /* if this isn't a bcast then we should send a negative reply XXXX */
  1110.        DEBUG(3,("no recursion\n"));
  1111. -      add_netbios_entry(qname,name_type,NB_ACTIVE,60*60,DNSFAIL,
  1112. -                dns_ip,False);
  1113. +      add_netbios_entry(qname,name_type,NB_ACTIVE,60*60,DNSFAIL,dns_ip,True);
  1114.        return NULL;
  1115.      }
  1116.        
  1117.        /* add it to our cache of names. give it 2 hours in the cache */
  1118. -      n = add_netbios_entry(qname,name_type,NB_ACTIVE,2*60*60,DNS,
  1119. -                dns_ip,False);
  1120. +      n = add_netbios_entry(qname,name_type,NB_ACTIVE,2*60*60,DNS,dns_ip,True);
  1121.        
  1122.        /* failed to add it? yikes! */
  1123.        if (!n) return NULL;
  1124. @@ -702,45 +735,25 @@
  1125.  }
  1126.  
  1127.  
  1128. -/***************************************************************************
  1129. -reply to a name query.
  1130. -
  1131. -with broadcast name queries:
  1132. -
  1133. -    - only reply if the query is for one of YOUR names. all other machines on
  1134. -      the network will be doing the same thing (that is, only replying to a
  1135. -      broadcast query if they own it)
  1136. -      NOTE: broadcast name queries should only be sent out by a machine
  1137. -      if they HAVEN'T been configured to use WINS. this is generally bad news
  1138. -      in a wide area tcp/ip network and should be rectified by the systems
  1139. -      administrator. USE WINS! :-)
  1140. -    - the exception to this is if the query is for a Primary Domain Controller
  1141. -      type name (0x1b), in which case, a reply is sent.
  1142.  
  1143. -    - NEVER send a negative response to a broadcast query. no-one else will!
  1144. -
  1145. -with directed name queries:
  1146. -
  1147. -    - if you are the WINS server, you are expected to 
  1148. -****************************************************************************/
  1149. -extern void reply_name_query(struct packet_struct *p)
  1150. +/***************************************************************************
  1151. +  reply to a name query
  1152. +  ****************************************************************************/
  1153. +void reply_name_query(struct packet_struct *p)
  1154.  {
  1155.    struct nmb_packet *nmb = &p->packet.nmb;
  1156.    struct nmb_name *question = &nmb->question.question_name;
  1157.    int name_type = question->name_type;
  1158. -  BOOL dns_type = name_type == 0x20 || name_type == 0;
  1159. +  BOOL dns_type = name_type == 0x20 || name_type == 0; 
  1160.    BOOL bcast = nmb->header.nm_flags.bcast;
  1161.    int ttl=0;
  1162.    int rcode = 0;
  1163.    int nb_flags = 0;
  1164.    struct in_addr retip;
  1165.    char rdata[6];
  1166. -  
  1167. -  struct in_addr gp_ip = *interpret_addr2("255.255.255.255");
  1168.    BOOL success = True;
  1169. -  
  1170.    struct name_record *n;
  1171. -  enum name_search search = dns_type || name_type == 0x1b ?
  1172. +  enum name_search search = (dns_type || name_type == 0x1b) ?
  1173.      FIND_GLOBAL : FIND_SELF;
  1174.  
  1175.    DEBUG(3,("Name query "));
  1176. @@ -756,8 +769,8 @@
  1177.          return;
  1178.        }
  1179.      }
  1180. -      
  1181. -      /* we will reply */
  1182. +
  1183. +      /* name is directed query, or it's self, or it's a PDC type name */
  1184.        ttl = n->death_time - p->timestamp;
  1185.        retip = n->ip;
  1186.        nb_flags = n->nb_flags;
  1187. @@ -767,13 +780,10 @@
  1188.        if (bcast) return; /* never reply negative response to bcasts */
  1189.        success = False;
  1190.      }
  1191. -  
  1192. -  /* if asking for a group name (type 0x1e) return 255.255.255.255 */
  1193. -  if (ip_equal(retip, gp_ip) && name_type == 0x1e) retip = gp_ip;
  1194.  
  1195.    /* if the IP is 0 then substitute my IP */
  1196.    if (zero_ip(retip)) retip = *iface_ip(p->ip);
  1197. -
  1198. +  
  1199.    if (success)
  1200.      {
  1201.        rcode = 0;
  1202. @@ -792,13 +802,15 @@
  1203.        putip(&rdata[2],(char *)&retip);
  1204.      }
  1205.    
  1206. -  reply_netbios_packet(p,nmb->header.name_trn_id,rcode,0,
  1207. +  reply_netbios_packet(p,nmb->header.name_trn_id,
  1208. +               rcode,0,True,
  1209.                 &nmb->question.question_name,
  1210.                 nmb->question.question_type,
  1211.                 nmb->question.question_class,
  1212.                 ttl,
  1213.                 rdata, success ? 6 : 0);
  1214.  }
  1215. +
  1216.  
  1217.  
  1218.  /****************************************************************************
  1219. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/source/nameserv.h samba-1.9.16alpha9/source/nameserv.h
  1220. --- samba-1.9.16alpha8/source/nameserv.h    Thu Jun  6 01:44:17 1996
  1221. +++ samba-1.9.16alpha9/source/nameserv.h    Sat Jun  8 15:37:53 1996
  1222. @@ -56,6 +56,9 @@
  1223.  #define NAME_MFLAG(p)     (((p) & NB_FLGMSK) == NB_MFLAG)
  1224.  #define NAME__FLAG(p)     (((p) & NB_FLGMSK) == NB__FLAG)
  1225.  
  1226. +#define MSBROWSE "\001\002__MSBROWSE__\002"
  1227. +
  1228. +enum name_search { FIND_SELF, FIND_GLOBAL };
  1229.  enum name_source {STATUS_QUERY, LMHOSTS, REGISTER, SELF, DNS, DNSFAIL};
  1230.  enum node_type {B_NODE=0, P_NODE=1, M_NODE=2, NBDD_NODE=3};
  1231.  enum packet_type {NMB_PACKET, DGRAM_PACKET};
  1232. @@ -260,14 +263,32 @@
  1233.  #define AM_DOMCTL(work) (work->ServerType & SV_TYPE_DOMAIN_CTRL)
  1234.  
  1235.  
  1236. -#define ANN_HostAnnouncement  1
  1237. -#define ANN_AnnouncementRequest 2
  1238. -#define ANN_Election 8
  1239. -#define ANN_GetBackupListReq 9
  1240. -#define ANN_GetBackupListResp 10
  1241. -#define ANN_BecomeBackup 11
  1242. -#define ANN_DomainAnnouncement 12
  1243. -#define ANN_MasterAnnouncement 13
  1244. -#define ANN_ResetBrowserState 14
  1245. +/* ids for netbios packet types */
  1246. +#define ANN_HostAnnouncement         1
  1247. +#define ANN_AnnouncementRequest      2
  1248. +#define ANN_Election                 8
  1249. +#define ANN_GetBackupListReq         9
  1250. +#define ANN_GetBackupListResp       10
  1251. +#define ANN_BecomeBackup            11
  1252. +#define ANN_DomainAnnouncement      12
  1253. +#define ANN_MasterAnnouncement      13
  1254. +#define ANN_ResetBrowserState       14
  1255.  #define ANN_LocalMasterAnnouncement 15
  1256. +
  1257. +
  1258. +/* broadcast packet announcement intervals, in minutes */
  1259. +
  1260. +/* search for master browsers of workgroups samba knows about, 
  1261. +   except default */
  1262. +#define CHECK_TIME_MST_BROWSE       5 
  1263. +
  1264. +/* request backup browser announcements from other servers */
  1265. +#define CHECK_TIME_ANNOUNCE_BACKUP 15
  1266. +
  1267. +/* request host announcements from other servers: min and max of interval */
  1268. +#define CHECK_TIME_MIN_HOST_ANNCE   3
  1269. +#define CHECK_TIME_MAX_HOST_ANNCE  12
  1270. +
  1271. +/* announce as master to WINS server and any Primary Domain Controllers */
  1272. +#define CHECK_TIME_MST_ANNOUNCE    15
  1273.  
  1274. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/source/namework.c samba-1.9.16alpha9/source/namework.c
  1275. --- samba-1.9.16alpha8/source/namework.c    Thu Jun  6 21:57:22 1996
  1276. +++ samba-1.9.16alpha9/source/namework.c    Sat Jun  8 15:37:54 1996
  1277. @@ -71,7 +71,6 @@
  1278.  #define AM_MASTER(work) (work->ServerType & SV_TYPE_MASTER_BROWSER)
  1279.  #define AM_BACKUP(work) (work->ServerType & SV_TYPE_BACKUP_BROWSER)
  1280.  
  1281. -#define MSBROWSE "\001\002__MSBROWSE__\002"
  1282.  #define BROWSE_MAILSLOT "\\MAILSLOT\\BROWSE"
  1283.  
  1284.  #define GET_TTL(ttl) ((ttl)?MIN(ttl,lp_max_ttl()):lp_max_ttl())
  1285. @@ -270,16 +269,19 @@
  1286.  /****************************************************************************
  1287.    add the default workgroup into my domain
  1288.    **************************************************************************/
  1289. -void add_my_domains(void)
  1290. +void add_my_domains(char *group)
  1291.  {
  1292. -  /* add or find domain on our local subnet, in the default workgroup */
  1293. -  
  1294. -  if (*lp_workgroup() != '*')
  1295. -    {
  1296. -      add_domain_entry(*iface_bcast(ipzero),
  1297. -               *iface_nmask(ipzero),
  1298. -               lp_workgroup(), True);
  1299. -    }
  1300. +  int n,i;
  1301. +  struct in_addr *ip;
  1302. +
  1303. +  if (*group == '*') return;
  1304. +
  1305. +  n = iface_count();
  1306. +  for (i=0;i<n;i++) {
  1307. +    ip = iface_n_ip(i);
  1308. +    if (!ip) return;
  1309. +    add_domain_entry(*iface_bcast(*ip),*iface_nmask(*ip),lp_workgroup(),True);
  1310. +  }
  1311.  }
  1312.  
  1313.  
  1314. @@ -649,7 +651,7 @@
  1315.  {
  1316.    struct dgram_packet *dgram = &p->packet.dgram;
  1317.    struct in_addr ip = dgram->header.source_ip;
  1318. -  struct domain_record *d; /* = find_domain(ip); */
  1319. +  struct domain_record *d; 
  1320.    struct work_record *work;
  1321.  
  1322.    int count = CVAL(buf,0);
  1323. @@ -728,7 +730,7 @@
  1324.        struct work_record *work;
  1325.        for (work=d->workgrouplist;work;work=remove_workgroup(d,work));
  1326.      }
  1327. -      add_my_domains();
  1328. +      add_my_domains(lp_workgroup());
  1329.      }
  1330.    
  1331.    /* stop browsing altogether. i don't think this is a good idea! */
  1332. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/source/nmbd.c samba-1.9.16alpha9/source/nmbd.c
  1333. --- samba-1.9.16alpha8/source/nmbd.c    Thu Jun  6 21:57:22 1996
  1334. +++ samba-1.9.16alpha9/source/nmbd.c    Sat Jun  8 15:37:54 1996
  1335. @@ -55,6 +55,28 @@
  1336.  extern struct in_addr ipzero;
  1337.  
  1338.  
  1339. + /****************************************************************************
  1340. +catch a sigterm
  1341. +****************************************************************************/
  1342. +static int sig_term()
  1343. +{
  1344. +  BlockSignals(True);
  1345. +  
  1346. +  DEBUG(0,("Got SIGTERM: going down...\n"));
  1347. +  
  1348. +  dump_names();
  1349. +  reload_services(True);
  1350. +  
  1351. +  /* remove all samba names, with wins server if necessary. */
  1352. +  remove_my_names();
  1353. +  
  1354. +  /* XXXX don't care if we never receive a response back... yet */
  1355. +  /* XXXX other things: if we are a master browser, force an election? */
  1356. +  
  1357. +  exit(0);
  1358. +}
  1359. +
  1360. +
  1361.  /****************************************************************************
  1362.  catch a sighup
  1363.  ****************************************************************************/
  1364. @@ -267,7 +289,7 @@
  1365.      if (group) {
  1366.        add_domain_entry(ipaddr, ipmask, name, True);
  1367.      } else {
  1368. -      add_netbios_entry(name,0x20,NB_ACTIVE,0,source,ipaddr,False);
  1369. +      add_netbios_entry(name,0x20,NB_ACTIVE,0,source,ipaddr,True);
  1370.      }
  1371.        }
  1372.      }
  1373. @@ -426,8 +448,9 @@
  1374.    fault_setup(fault_continue);
  1375.  
  1376.    signal(SIGHUP,SIGNAL_CAST sig_hup);
  1377. +  signal(SIGTERM,SIGNAL_CAST sig_term);
  1378.  
  1379. -  while ((opt = getopt (argc, argv, "s:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:")) != EOF)
  1380. +  while ((opt = getopt(argc, argv, "s:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:")) != EOF)
  1381.      {
  1382.        switch (opt)
  1383.      {
  1384. @@ -492,7 +515,7 @@
  1385.      return(-1);    
  1386.  
  1387.    if (*group)
  1388. -    add_domain_entry(*iface_bcast(ipzero),*iface_nmask(ipzero),group, True);
  1389. +    add_my_domains(group);
  1390.  
  1391.    if (!is_daemon && !is_a_socket(0)) {
  1392.      DEBUG(0,("standard input is not a socket, assuming -D option\n"));
  1393. @@ -519,7 +542,7 @@
  1394.    string_sub(ServerComment,"%h",myhostname);
  1395.  
  1396.    add_my_names();
  1397. -  add_my_domains();
  1398. +  add_my_domains(lp_workgroup());
  1399.  
  1400.    DEBUG(3,("Checked names\n"));
  1401.    
  1402. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/source/nmblookup.c samba-1.9.16alpha9/source/nmblookup.c
  1403. --- samba-1.9.16alpha8/source/nmblookup.c    Thu Jun  6 21:57:23 1996
  1404. +++ samba-1.9.16alpha9/source/nmblookup.c    Sat Jun  8 15:37:54 1996
  1405. @@ -93,7 +93,7 @@
  1406.  int main(int argc,char *argv[])
  1407.  {
  1408.    int opt;
  1409. -  unsigned int lookup_type = 0x20;
  1410. +  unsigned int lookup_type = 0;
  1411.    pstring lookup;
  1412.    extern int optind;
  1413.    extern char *optarg;
  1414. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/source/nmbsync.c samba-1.9.16alpha9/source/nmbsync.c
  1415. --- samba-1.9.16alpha8/source/nmbsync.c    Thu Jun  6 21:57:23 1996
  1416. +++ samba-1.9.16alpha9/source/nmbsync.c    Fri Jun  7 15:36:53 1996
  1417. @@ -103,7 +103,6 @@
  1418.            uint32 stype = IVAL(p,18);
  1419.            int comment_offset = IVAL(p,22) & 0xFFFF;
  1420.            char *cmnt = comment_offset?(rdata+comment_offset-converter):"";
  1421. -          
  1422.            struct work_record *w = work;
  1423.            
  1424.            DEBUG(4, ("\t%-16.16s     %08x    %s\n", sname, stype, cmnt));
  1425. @@ -111,16 +110,17 @@
  1426.            if (stype & SV_TYPE_DOMAIN_ENUM)
  1427.          {
  1428.            /* creates workgroup on remote subnet */
  1429. -          if ((w = find_workgroupstruct(d,sname, False)))
  1430. +          if ((w = find_workgroupstruct(d,sname, True)))
  1431.              {
  1432.                if (ismybcast(d->bcast_ip))
  1433.              {
  1434.                announce_request(w, d->bcast_ip);
  1435.              }
  1436.              }
  1437. -        }
  1438. +        }          
  1439.            
  1440. -          add_server_entry(d,w,sname,stype,lp_max_ttl(),cmnt,False);
  1441. +          if (w)
  1442. +        add_server_entry(d,w,sname,stype,lp_max_ttl(),cmnt,False);
  1443.          }
  1444.      }
  1445.      }
  1446. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/source/predict.c samba-1.9.16alpha9/source/predict.c
  1447. --- samba-1.9.16alpha8/source/predict.c    Thu Jan  1 10:00:00 1970
  1448. +++ samba-1.9.16alpha9/source/predict.c    Fri Jun  7 13:33:59 1996
  1449. @@ -0,0 +1,146 @@
  1450. +/* 
  1451. +   Unix SMB/Netbios implementation.
  1452. +   Version 1.9.
  1453. +   file read prediction routines
  1454. +   Copyright (C) Andrew Tridgell 1992-1995
  1455. +   
  1456. +   This program is free software; you can redistribute it and/or modify
  1457. +   it under the terms of the GNU General Public License as published by
  1458. +   the Free Software Foundation; either version 2 of the License, or
  1459. +   (at your option) any later version.
  1460. +   
  1461. +   This program is distributed in the hope that it will be useful,
  1462. +   but WITHOUT ANY WARRANTY; without even the implied warranty of
  1463. +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1464. +   GNU General Public License for more details.
  1465. +   
  1466. +   You should have received a copy of the GNU General Public License
  1467. +   along with this program; if not, write to the Free Software
  1468. +   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1469. +*/
  1470. +
  1471. +#include "includes.h"
  1472. +#include "loadparm.h"
  1473. +
  1474. +extern int DEBUGLEVEL;
  1475. +
  1476. +
  1477. +/* variables used by the read prediction module */
  1478. +static int rp_fd = -1;
  1479. +static int rp_offset = 0;
  1480. +static int rp_length = 0;
  1481. +static int rp_alloced = 0;
  1482. +static int rp_predict_fd = -1;
  1483. +static int rp_predict_offset = 0;
  1484. +static int rp_predict_length = 0;
  1485. +static int rp_timeout = 5;
  1486. +static time_t rp_time = 0;
  1487. +static char *rp_buffer = NULL;
  1488. +static BOOL predict_skip=False;
  1489. +time_t smb_last_time=(time_t)0;
  1490. +
  1491. +/****************************************************************************
  1492. +handle read prediction on a file
  1493. +****************************************************************************/
  1494. +int read_predict(int fd,int offset,char *buf,char **ptr,int num)
  1495. +{
  1496. +  int ret = 0;
  1497. +  int possible = rp_length - (offset - rp_offset);
  1498. +
  1499. +  possible = MIN(possible,num);
  1500. +
  1501. +  /* give data if possible */
  1502. +  if (fd == rp_fd && 
  1503. +      offset >= rp_offset && 
  1504. +      possible>0 &&
  1505. +      smb_last_time-rp_time < rp_timeout)
  1506. +    {
  1507. +      ret = possible;
  1508. +      if (buf)
  1509. +    memcpy(buf,rp_buffer + (offset-rp_offset),possible);
  1510. +      else
  1511. +    *ptr = rp_buffer + (offset-rp_offset);
  1512. +      DEBUG(5,("read-prediction gave %d bytes of %d\n",ret,num));
  1513. +    }
  1514. +
  1515. +  if (ret == num) {
  1516. +    predict_skip = True;
  1517. +  } else {
  1518. +    predict_skip = False;
  1519. +
  1520. +    /* prepare the next prediction */
  1521. +    rp_predict_fd = fd;
  1522. +    rp_predict_offset = offset + num;
  1523. +    rp_predict_length = num;
  1524. +  }
  1525. +
  1526. +  if (ret < 0) ret = 0;
  1527. +
  1528. +  return(ret);
  1529. +}
  1530. +
  1531. +/****************************************************************************
  1532. +pre-read some data
  1533. +****************************************************************************/
  1534. +void do_read_prediction()
  1535. +{
  1536. +  static int readsize = 0;
  1537. +
  1538. +  if (predict_skip) return;
  1539. +
  1540. +  if (rp_predict_fd == -1) 
  1541. +    return;
  1542. +
  1543. +  rp_fd = rp_predict_fd;
  1544. +  rp_offset = rp_predict_offset;
  1545. +  rp_length = 0;
  1546. +
  1547. +  rp_predict_fd = -1;
  1548. +
  1549. +  if (readsize == 0) {
  1550. +    readsize = lp_readsize();
  1551. +    readsize = MAX(readsize,1024);
  1552. +  }
  1553. +
  1554. +  rp_predict_length = MIN(rp_predict_length,2*readsize);
  1555. +  rp_predict_length = MAX(rp_predict_length,1024);
  1556. +  rp_offset = (rp_offset/1024)*1024;
  1557. +  rp_predict_length = (rp_predict_length/1024)*1024;
  1558. +
  1559. +  if (rp_predict_length > rp_alloced)
  1560. +    {
  1561. +      rp_buffer = Realloc(rp_buffer,rp_predict_length);
  1562. +      rp_alloced = rp_predict_length;
  1563. +      if (!rp_buffer)
  1564. +    {
  1565. +      DEBUG(0,("can't allocate read-prediction buffer\n"));
  1566. +      rp_predict_fd = -1;
  1567. +      rp_fd = -1;
  1568. +      rp_alloced = 0;
  1569. +      return;
  1570. +    }
  1571. +    }
  1572. +
  1573. +  if (lseek(rp_fd,rp_offset,SEEK_SET) != rp_offset) {
  1574. +    rp_fd = -1;
  1575. +    rp_predict_fd = -1;
  1576. +    return;
  1577. +  }
  1578. +
  1579. +  rp_length = read(rp_fd,rp_buffer,rp_predict_length);
  1580. +  rp_time = time(NULL);
  1581. +  if (rp_length < 0)
  1582. +    rp_length = 0;
  1583. +}
  1584. +
  1585. +/****************************************************************************
  1586. +invalidate read-prediction on a fd
  1587. +****************************************************************************/
  1588. +void invalidate_read_prediction(int fd)
  1589. +{
  1590. + if (rp_fd == fd) 
  1591. +   rp_fd = -1;
  1592. + if (rp_predict_fd == fd)
  1593. +   rp_predict_fd = -1;
  1594. +}
  1595. +
  1596. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/source/proto.h samba-1.9.16alpha9/source/proto.h
  1597. --- samba-1.9.16alpha8/source/proto.h    Thu Jun  6 21:57:24 1996
  1598. +++ samba-1.9.16alpha9/source/proto.h    Sat Jun  8 15:37:54 1996
  1599. @@ -67,6 +67,8 @@
  1600.  void iface_set_default(char *ip,char *bcast,char *nmask);
  1601.  BOOL ismyip(struct in_addr ip);
  1602.  BOOL ismybcast(struct in_addr bcast);
  1603. +int iface_count(void);
  1604. +struct in_addr *iface_n_ip(int n);
  1605.  struct in_addr *iface_bcast(struct in_addr ip);
  1606.  struct in_addr *iface_nmask(struct in_addr ip);
  1607.  struct in_addr *iface_ip(struct in_addr ip);
  1608. @@ -147,9 +149,9 @@
  1609.          BOOL bcast,BOOL recurse,
  1610.          struct in_addr to_ip, struct in_addr *ip,void (*fn)());
  1611.  void expire_netbios_response_entries(time_t t);
  1612. -void reply_netbios_packet(struct packet_struct *p1,int trn_id,int rcode,int opcode,
  1613. -              struct nmb_name *rr_name,int rr_type,int rr_class,int ttl,
  1614. -              char *data,int len);
  1615. +void reply_netbios_packet(struct packet_struct *p1,int trn_id,int rcode,
  1616. +              int opcode,BOOL recurse,struct nmb_name *rr_name,
  1617. +              int rr_type,int rr_class,int ttl,char *data,int len);
  1618.  uint16 initiate_netbios_packet(int fd,int quest_type,char *name,int name_type,
  1619.                     int nb_flags,BOOL bcast,BOOL recurse,
  1620.                     struct in_addr to_ip);
  1621. @@ -180,6 +182,7 @@
  1622.  void remove_name_entry(char *name,int type);
  1623.  void add_name_entry(char *name,int type,int nb_flags);
  1624.  void add_my_names(void);
  1625. +void remove_my_names();
  1626.  void refresh_my_names(time_t t);
  1627.  void expire_names(time_t t);
  1628.  void response_name_release(struct packet_struct *p);
  1629. @@ -187,8 +190,7 @@
  1630.  void response_name_reg(struct packet_struct *p);
  1631.  void reply_name_reg(struct packet_struct *p);
  1632.  void reply_name_status(struct packet_struct *p);
  1633. -struct name_record *search_for_name(struct nmb_name *question,
  1634. -                    struct in_addr ip, int Time, int search);
  1635. +void reply_name_query(struct packet_struct *p);
  1636.  void process_nmb(struct packet_struct *p);
  1637.  void reset_server(char *name, int state, struct in_addr ip);
  1638.  void tell_become_backup(void);
  1639. @@ -197,7 +199,7 @@
  1640.           int name_type,
  1641.           struct in_addr ip);
  1642.  void update_from_reg(char *name, int type, struct in_addr ip);
  1643. -void add_my_domains(void);
  1644. +void add_my_domains(char *group);
  1645.  BOOL same_context(struct dgram_packet *dgram);
  1646.  BOOL listening_name(struct work_record *work, struct nmb_name *n);
  1647.  void process_logon_packet(struct packet_struct *p,char *buf,int len);
  1648. @@ -239,12 +241,19 @@
  1649.  BOOL server_validate(char *buf);
  1650.  BOOL pcap_printername_ok(char *pszPrintername, char *pszPrintcapname);
  1651.  void pcap_printer_fn(void (*fn)());
  1652. +int read_predict(int fd,int offset,char *buf,char **ptr,int num);
  1653. +void do_read_prediction();
  1654. +void invalidate_read_prediction(int fd);
  1655.  void lpq_reset(int snum);
  1656.  void print_file(int fnum);
  1657.  int get_printqueue(int snum,int cnum,print_queue_struct **queue,
  1658.             print_status_struct *status);
  1659.  void del_printqueue(int cnum,int snum,int jobid);
  1660.  void status_printjob(int cnum,int snum,int jobid,int status);
  1661. +BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize);
  1662. +BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize);
  1663. +BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize);
  1664. +BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize);
  1665.  int reply_special(char *inbuf,char *outbuf);
  1666.  int reply_tcon(char *inbuf,char *outbuf);
  1667.  int reply_tcon_and_X(char *inbuf,char *outbuf,int length,int bufsize);
  1668. @@ -457,9 +466,6 @@
  1669.  BOOL send_keepalive(int client);
  1670.  int read_data(int fd,char *buffer,int N);
  1671.  int write_data(int fd,char *buffer,int N);
  1672. -int read_predict(int fd,int offset,char *buf,char **ptr,int num);
  1673. -void do_read_prediction();
  1674. -void invalidate_read_prediction(int fd);
  1675.  int transfer_file(int infd,int outfd,int n,char *header,int headlen,int align);
  1676.  int read_smb_length(int fd,char *inbuf,int timeout);
  1677.  BOOL receive_smb(int fd,char *buffer,int timeout);
  1678. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/source/quotas.c samba-1.9.16alpha9/source/quotas.c
  1679. --- samba-1.9.16alpha8/source/quotas.c    Wed Jun  5 01:16:28 1996
  1680. +++ samba-1.9.16alpha9/source/quotas.c    Sat Jun  8 15:37:54 1996
  1681. @@ -29,6 +29,7 @@
  1682.  
  1683.  #include "includes.h"
  1684.  
  1685. +extern int DEBUGLEVEL;
  1686.  
  1687.  #ifdef LINUX
  1688.  
  1689. @@ -50,7 +51,7 @@
  1690.  */
  1691.  #include "quota/quotactl.c"
  1692.  #include "quota/hasquota.c"
  1693. -static BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
  1694. +BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
  1695.  {
  1696.    uid_t euser_id;
  1697.    struct dqblk D;
  1698. @@ -139,7 +140,7 @@
  1699.  /****************************************************************************
  1700.  try to get the disk space from disk quotas (CRAY VERSION)
  1701.  ****************************************************************************/
  1702. -static BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
  1703. +BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
  1704.  {
  1705.    struct mntent *mnt;
  1706.    FILE *fd;
  1707. @@ -233,48 +234,119 @@
  1708.  }
  1709.  
  1710.  
  1711. -#elif defined(SUNOS5)
  1712. +#elif defined(SUNOS5) || defined(SUNOS4)
  1713.  
  1714. -#include <devnm.h>
  1715.  #include <fcntl.h>
  1716. +#if defined(SUNOS5)
  1717.  #include <sys/fs/ufs_quota.h>
  1718. +#include <sys/mnttab.h>
  1719. +#else /* defined(SUNOS4) */
  1720. +#include <ufs/quota.h>
  1721. +#include <mntent.h>
  1722. +#endif
  1723.  
  1724.  /****************************************************************************
  1725.  try to get the disk space from disk quotas (solaris 2 version)
  1726.  ****************************************************************************/
  1727.  /* Quota code by Peter Urbanec (amiga@cse.unsw.edu.au) */
  1728. -static BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
  1729. +BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
  1730.  {
  1731.    uid_t user_id, euser_id;
  1732. -  int r;
  1733. +  int ret;
  1734.    struct dqblk D;
  1735. +#if defined(SUNOS5)
  1736.    struct quotctl command;
  1737.    int file;
  1738. -  int ret;
  1739. -  if((file=open(path, O_RDONLY))<0) return(False);
  1740. +  struct mnttab mnt;
  1741. +  static char name[MNT_LINE_MAX] ;
  1742. +#else
  1743. +  struct mntent *mnt;
  1744. +  static char name[MNTMAXSTR] ;
  1745. +#endif
  1746. +  FILE *fd;
  1747. +  struct stat sbuf;
  1748. +  dev_t devno ;
  1749. +  static dev_t devno_cached = 0 ;
  1750. +  int found ;
  1751. +  
  1752. +  if ( stat(path,&sbuf) == -1 )
  1753. +    return(False) ;
  1754. +  
  1755. +  devno = sbuf.st_dev ;
  1756. +DEBUG(5,("disk_quotas: looking for path \"%s\" devno=%o\n", path,devno));
  1757. +  if ( devno != devno_cached ) {
  1758. +    devno_cached = devno ;
  1759. +#if defined(SUNOS5)
  1760. +    if ((fd = fopen(MNTTAB, "r")) == NULL)
  1761. +      return(False) ;
  1762. +    
  1763. +    found = False ;
  1764. +    while (getmntent(fd, &mnt) == 0) {
  1765. +      if ( stat(mnt.mnt_mountp,&sbuf) == -1 )
  1766. +    continue ;
  1767. +DEBUG(5,("disk_quotas: testing \"%s\" devno=%o\n", mnt.mnt_mountp,sbuf.st_dev));
  1768. +      if (sbuf.st_dev == devno) {
  1769. +    found = True ;
  1770. +    break ;
  1771. +      }
  1772. +    }
  1773. +    
  1774. +    strcpy(name,mnt.mnt_mountp) ;
  1775. +    strcat(name,"/quotas") ;
  1776. +    fclose(fd) ;
  1777. +#else
  1778. +    if ((fd = setmntent(MOUNTED, "r")) == NULL)
  1779. +      return(False) ;
  1780. +    
  1781. +    found = False ;
  1782. +    while ((mnt = getmntent(fd)) != NULL) {
  1783. +      if ( stat(mnt->mnt_dir,&sbuf) == -1 )
  1784. +    continue ;
  1785. +DEBUG(5,("disk_quotas: testing \"%s\" devno=%o\n", mnt->mnt_dir,sbuf.st_dev));
  1786. +      if (sbuf.st_dev == devno) {
  1787. +    found = True ;
  1788. +    break ;
  1789. +      }
  1790. +    }
  1791. +    
  1792. +    strcpy(name,mnt->mnt_fsname) ;
  1793. +    endmntent(fd) ;
  1794. +#endif
  1795. +    
  1796. +    if ( ! found )
  1797. +      return(False) ;
  1798. +  }
  1799.  
  1800.    euser_id = geteuid();
  1801.    user_id = getuid();
  1802.  
  1803. -  command.op = Q_GETQUOTA;
  1804. -  command.uid = euser_id;
  1805. -  command.addr = (caddr_t) &D;
  1806.    setuid(0);  /* Solaris seems to want to give info only to super-user */
  1807.    seteuid(0);
  1808.  
  1809. +#if defined(SUNOS5)
  1810. +DEBUG(5,("disk_quotas: looking for quotas file \"%s\"\n", name));
  1811. +  if((file=open(name, O_RDONLY))<0) {
  1812. +    setuid(user_id);  /* Restore the original UID status */
  1813. +    seteuid(euser_id);
  1814. +    return(False);
  1815. +  }
  1816. +  command.op = Q_GETQUOTA;
  1817. +  command.uid = euser_id;
  1818. +  command.addr = (caddr_t) &D;
  1819.    ret = ioctl(file, Q_QUOTACTL, &command);
  1820. +  close(file);
  1821. +#else
  1822. +DEBUG(5,("disk_quotas: trying quotactl on device \"%s\"\n", name));
  1823. +  ret = quotactl(Q_GETQUOTA, name, euser_id, &D);
  1824. +#endif
  1825.  
  1826.    setuid(user_id);  /* Restore the original UID status */
  1827.    seteuid(euser_id);
  1828.  
  1829.    if (ret < 0) {
  1830. -    close(file);
  1831.      DEBUG(2,("disk_quotas ioctl (Solaris) failed\n"));
  1832.      return(False);
  1833.    }
  1834. -  close(file);
  1835.  
  1836.  
  1837.    /* Use softlimit to determine disk space. A user exceeding the quota is told
  1838. @@ -283,6 +355,8 @@
  1839.     * made of rubber latex and begins to expand to accommodate the user :-)
  1840.     */
  1841.  
  1842. +  if (D.dqb_bsoftlimit==0)
  1843. +    return(False);
  1844.    *bsize = 512;
  1845.    *dfree = D.dqb_bsoftlimit - D.dqb_curblocks;
  1846.    *dsize = D.dqb_bsoftlimit;
  1847. @@ -306,7 +380,7 @@
  1848.  /****************************************************************************
  1849.  try to get the disk space from disk quotas - default version
  1850.  ****************************************************************************/
  1851. -static BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
  1852. +BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
  1853.  {
  1854.    uid_t user_id, euser_id;
  1855.    int r;
  1856. @@ -341,6 +415,8 @@
  1857.      }
  1858.        else return(False);
  1859.      }
  1860. +  if (D.dqb_bsoftlimit==0)
  1861. +    return(False);
  1862.    /* Use softlimit to determine disk space, except when it has been exceeded */
  1863.    if ((D.dqb_curblocks>D.dqb_bsoftlimit)||(D.dqb_curfiles>D.dqb_fsoftlimit)) 
  1864.      {
  1865. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/source/util.c samba-1.9.16alpha9/source/util.c
  1866. --- samba-1.9.16alpha8/source/util.c    Thu Jun  6 21:57:24 1996
  1867. +++ samba-1.9.16alpha9/source/util.c    Fri Jun  7 15:36:55 1996
  1868. @@ -56,10 +56,6 @@
  1869.  */
  1870.  int case_default = CASE_LOWER;
  1871.  
  1872. -
  1873. -/* size of reads during a direct file to file transfer */
  1874. -int ReadSize = 16*1024;
  1875. -
  1876.  pstring debugf = "/tmp/log.samba";
  1877.  int syslog_level;
  1878.  
  1879. @@ -1951,7 +1947,6 @@
  1880.        
  1881.        /* Check if error */
  1882.        if(selrtn == -1) {
  1883. -    errno = EBADF;
  1884.      return -1;
  1885.        }
  1886.        
  1887. @@ -1974,7 +1969,6 @@
  1888.      /* force a particular error number for
  1889.         portability */
  1890.      DEBUG(5,("read gave error %s\n",strerror(errno)));
  1891. -    errno = EBADF;
  1892.      return -1;
  1893.        }
  1894.        
  1895. @@ -2068,10 +2062,6 @@
  1896.      {
  1897.        ret = read(fd,buffer + total,N - total);
  1898.  
  1899. -      /* this is for portability */
  1900. -      if (ret < 0)
  1901. -    errno = EBADF;
  1902. -
  1903.        if (ret <= 0)
  1904.      return total;
  1905.        total += ret;
  1906. @@ -2101,142 +2091,28 @@
  1907.  }
  1908.  
  1909.  
  1910. -/* variables used by the read prediction module */
  1911. -int rp_fd = -1;
  1912. -int rp_offset = 0;
  1913. -int rp_length = 0;
  1914. -int rp_alloced = 0;
  1915. -int rp_predict_fd = -1;
  1916. -int rp_predict_offset = 0;
  1917. -int rp_predict_length = 0;
  1918. -int rp_timeout = 5;
  1919. -time_t rp_time = 0;
  1920. -char *rp_buffer = NULL;
  1921. -BOOL predict_skip=False;
  1922. -time_t smb_last_time=(time_t)0;
  1923. -
  1924. -/****************************************************************************
  1925. -handle read prediction on a file
  1926. -****************************************************************************/
  1927. -int read_predict(int fd,int offset,char *buf,char **ptr,int num)
  1928. -{
  1929. -  int ret = 0;
  1930. -  int possible = rp_length - (offset - rp_offset);
  1931. -
  1932. -  possible = MIN(possible,num);
  1933. -
  1934. -  /* give data if possible */
  1935. -  if (fd == rp_fd && 
  1936. -      offset >= rp_offset && 
  1937. -      possible>0 &&
  1938. -      smb_last_time-rp_time < rp_timeout)
  1939. -    {
  1940. -      ret = possible;
  1941. -      if (buf)
  1942. -    memcpy(buf,rp_buffer + (offset-rp_offset),possible);
  1943. -      else
  1944. -    *ptr = rp_buffer + (offset-rp_offset);
  1945. -      DEBUG(5,("read-prediction gave %d bytes of %d\n",ret,num));
  1946. -    }
  1947. -
  1948. -  if (ret == num) {
  1949. -    predict_skip = True;
  1950. -  } else {
  1951. -    predict_skip = False;
  1952. -
  1953. -    /* prepare the next prediction */
  1954. -    rp_predict_fd = fd;
  1955. -    rp_predict_offset = offset + num;
  1956. -    rp_predict_length = num;
  1957. -  }
  1958. -
  1959. -  if (ret < 0) ret = 0;
  1960. -
  1961. -  return(ret);
  1962. -}
  1963. -
  1964. -/****************************************************************************
  1965. -pre-read some data
  1966. -****************************************************************************/
  1967. -void do_read_prediction()
  1968. -{
  1969. -  if (predict_skip) return;
  1970. -
  1971. -  if (rp_predict_fd == -1) 
  1972. -    return;
  1973. -
  1974. -  rp_fd = rp_predict_fd;
  1975. -  rp_offset = rp_predict_offset;
  1976. -  rp_length = 0;
  1977. -
  1978. -  rp_predict_fd = -1;
  1979. -
  1980. -  rp_predict_length = MIN(rp_predict_length,2*ReadSize);
  1981. -  rp_predict_length = MAX(rp_predict_length,1024);
  1982. -  rp_offset = (rp_offset/1024)*1024;
  1983. -  rp_predict_length = (rp_predict_length/1024)*1024;
  1984. -
  1985. -  if (rp_predict_length > rp_alloced)
  1986. -    {
  1987. -      rp_buffer = Realloc(rp_buffer,rp_predict_length);
  1988. -      rp_alloced = rp_predict_length;
  1989. -      if (!rp_buffer)
  1990. -    {
  1991. -      DEBUG(0,("can't allocate read-prediction buffer\n"));
  1992. -      rp_predict_fd = -1;
  1993. -      rp_fd = -1;
  1994. -      rp_alloced = 0;
  1995. -      return;
  1996. -    }
  1997. -    }
  1998. -
  1999. -  if (lseek(rp_fd,rp_offset,SEEK_SET) != rp_offset) {
  2000. -    rp_fd = -1;
  2001. -    rp_predict_fd = -1;
  2002. -    return;
  2003. -  }
  2004. -
  2005. -  rp_length = read(rp_fd,rp_buffer,rp_predict_length);
  2006. -  rp_time = time(NULL);
  2007. -  if (rp_length < 0)
  2008. -    rp_length = 0;
  2009. -}
  2010. -
  2011. -/****************************************************************************
  2012. -invalidate read-prediction on a fd
  2013. -****************************************************************************/
  2014. -void invalidate_read_prediction(int fd)
  2015. -{
  2016. - if (rp_fd == fd) 
  2017. -   rp_fd = -1;
  2018. - if (rp_predict_fd == fd)
  2019. -   rp_predict_fd = -1;
  2020. -}
  2021. -
  2022. -
  2023.  /****************************************************************************
  2024.  transfer some data between two fd's
  2025.  ****************************************************************************/
  2026.  int transfer_file(int infd,int outfd,int n,char *header,int headlen,int align)
  2027.  {
  2028.    static char *buf=NULL;  
  2029. +  static int size=0;
  2030.    char *buf1,*abuf;
  2031. -  static int size = 0;
  2032.    int total = 0;
  2033.  
  2034.    DEBUG(4,("transfer_file %d  (head=%d) called\n",n,headlen));
  2035.  
  2036. -  if ((size < ReadSize) && buf) {
  2037. -    free(buf);
  2038. -    buf = NULL;
  2039. +  if (size == 0) {
  2040. +    size = lp_readsize();
  2041. +    size = MAX(size,1024);
  2042.    }
  2043.  
  2044. -  size = MAX(ReadSize,1024);
  2045. -
  2046.    while (!buf && size>0) {
  2047.      buf = (char *)Realloc(buf,size+8);
  2048.      if (!buf) size /= 2;
  2049.    }
  2050. +
  2051.    if (!buf) {
  2052.      DEBUG(0,("Can't allocate transfer buffer!\n"));
  2053.      exit(1);
  2054. diff -u -r --new-file --exclude=CVS samba-1.9.16alpha8/source/version.h samba-1.9.16alpha9/source/version.h
  2055. --- samba-1.9.16alpha8/source/version.h    Thu Jun  6 21:57:49 1996
  2056. +++ samba-1.9.16alpha9/source/version.h    Sat Jun  8 15:38:39 1996
  2057. @@ -1 +1 @@
  2058. -#define VERSION "1.9.16alpha8"
  2059. +#define VERSION "1.9.16alpha9"
  2060.